package prj.stars;

import java.util.ArrayList;

import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.widget.TabHost;

/**
 * 
 * @author Andreea-Cristina Hodea
 *
 * Main activity: manages main view which is a tab view and changes configuration if needed (when rotating device).
 */
public class GradesActivity extends TabActivity {
	
	private ArrayList<String> groups = new ArrayList<String>();
	private final int HOW_MANY_GROUPS = 5;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        TabHost tabHost = getTabHost();
        // Resusable TabSpec for each tab
        TabHost.TabSpec spec;
        // Reusable Intent for each tab
        Intent intent;  

        // Existing groups
        for (int i = 1; i <= HOW_MANY_GROUPS; i++)
        	groups.add("33"+i+"CB");       
        
        for (int i = 1, size = groups.size(); i <= size; i++) {
        	String group = groups.get(i-1);
	        // Create an Intent to launch an Activity for the tab (to be reused)
	        intent = new Intent().setClass(this, GroupActivity.class);
	        intent.putExtra("group", group);
	        
	        // Initialize a TabSpec for each tab and add it to the TabHost
	        spec = tabHost.newTabSpec(group).setIndicator(group).setContent(intent);
	        tabHost.addTab(spec);
        }
        tabHost.setCurrentTab(5);
         
    }

    /** Reload content view when device is rotated. For this to work this line "android:configChanges="orientation">" 
     * 	should be added to manifest.xml file. 
     */
    public void onConfigurationChanged(Configuration newConfig) {
	    super.onConfigurationChanged(newConfig);
	    setContentView(R.layout.main);
	  }
}

